$('#checkFailPage').on('hidden.bs.modal', function () {
    $("#remark").val('');
});
$('#scanQrCodePage').on('hidden.bs.modal', function () {
    $("#scanCode").attr("src", '');
});

$(function () {
    initScanQrCodePage('minApp', 'check', doPass, unPass, refreshQrCode);
});

function showBizDocApp() {
    $('#_bizDocAppTD').addClass('active');
    $('#_bizDocAppFuncTD').removeClass('active');
    $('#_bizDocAppFuncDiv').css('display', 'none');
    $('#_bizDocAppDiv').css('display', 'block');
}

function showBizDocAppFunc() {
    $('#_bizDocAppFuncTD').addClass('active');
    $('#_bizDocAppTD').removeClass('active');
    $('#_bizDocAppDiv').css('display', 'none');
    $('#_bizDocAppFuncDiv').css('display', 'block');
}

function refreshQrCode() {
    var postData = {
        refCode : oneAfterDocAppInfo.refCode,
        appid : oneAfterDocAppInfo.appid,
        orgCode : oneAfterDocAppInfo.orgCode,
    };
    var url = basePath + 'checkApp/checkDocApp/getQrCode';
    doRefreshQrCode(url, postData, 'minApp');
}

function openViewPage() {
    var postData = {
        refCode : oneAfterDocAppInfo.refCode,
        appid : oneAfterDocAppInfo.appid,
        orgCode : oneAfterDocAppInfo.orgCode,
    };
    var url = basePath + 'checkApp/checkDocApp/getQrCode';
    doShowQrCode(url, postData, 'minApp');
}

//通过
function doPass() {
    var postData = {
        id : oneLogInfo.id,
        batchId : oneLogInfo.batchId,
        bizAppId : oneAfterDocAppInfo.id,
        docCode : oneAfterDocAppInfo.refCode,
        appCategory : "doctor",
        remark : '审核通过',
    };
    showLoading();
    $.ajax({
        type: 'post',
        url: basePath + 'checkApp/checkDocApp/checkPassBizDocApp?hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp ,
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            hideLoading();
            if(data.result){
                doClose();
            }else{
                toastr.error(data.message);
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
        }
    });
}

function unPass() {
    closeScanOrCodePage();
    $('#checkFailPage').modal('show');
}

function doUnPass() {
    var remark = $('#remark').val();
    if (!remark || remark.length == 0 ) {
        toastr.error('审核不通过原因不能为空');
        return;
    }
    var postData = {
        remark : remark,
        id : oneLogInfo.id,
        batchId : oneLogInfo.batchId,
        bizAppId : oneAfterDocAppInfo.id,
    };
    showLoading();
    $.ajax({
        type: 'post',
        url: basePath + 'checkApp/checkDocApp/checkFailBizDocApp?hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp ,
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            hideLoading();
            if(data.result){
                doClose();
            }else{
                toastr.error(data.message);
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
        }
    });
}


function closeScanOrCodePage() {
    $("#scanQrCodePage").modal('hide');
    $("#scanCode").attr("src", '');
}

function closeCheckFailPage() {
    $("#checkFailPage").modal('hide');
    $("#remark").val('');
}

function doClose() {
    var str = '&docName=' + searchLogInfo.docName + '&checkType=' + searchLogInfo.checkType + '&isvPid=' + searchLogInfo.isvPid + '&status='+
        searchLogInfo.status + '&isvName=' + searchLogInfo.isvName + '&orgCode=' + searchLogInfo.orgCode + '&orgName=' + searchLogInfo.orgName +
        '&bizCode=' + searchLogInfo.bizCode + '&timeInterval=' + searchLogInfo.timeInterval + '&timeInterval1=' + searchLogInfo.timeInterval1 +
        '&hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +
        '&result='+ searchLogInfo.result +'&pageSize=' + searchLogInfo.pageSize + '&pageNo=' + searchLogInfo.pageNo;
    window.location.href = basePath + 'checkApp/checkDocApp/checkDocAppPage?t=' + new Date().getTime() + str;
}